<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\logic;

use app\common\model\OtcOrder;
use app\common\model\OtcTrading;
use app\common\model\Transfer;
use app\common\model\UserAccountLog;
use app\common\model\UserRankingData;
use app\common\model\WithdrawalPayinfo;
use think\Db;

/**
 * Recharge逻辑
 */
class ShopSubsidy extends LogicBase
{
    

    
    /**
     * 获取补贴列表
     */
    public function subsidy_list($data = [], $field = 'a.*,c.username ', $order = '', $paginate = DB_LIST_ROWS)
    {
        


        $where = $where1 = [];
        if (!empty($data['date1']) && !empty($data['date2'])) {
            $where['a.create_time'] = ['between', [strtotime($data['date1'] . ' 00:00:00'), strtotime($data['date2'] . ' 23:59:59')]];
        }
        if (!empty($data['search_data'])) {
            $where['a.user_id|s.shop_name|c.username'] = $data['search_data'];
        }
        if (!empty($data['wallet_id'])) {
            $where['a.wallet_id'] = $data['wallet_id'];
        }
        !empty($data['state']) &&   $where['a.state'] = $data['state'];


        $list =  $this->modelOtcInterestLog->alias('a')->join('__MEMBER__ c' ,'a.user_id = c.id')->join('__OTC_SHOP__ s' ,'a.shop_id = s.id')->field($field)->where($where)->order($order)->paginate($paginate, false, ['query' => $data]);
        $count =  $this->modelOtcInterestLog->alias('a')->join('__MEMBER__ c' ,'a.user_id = c.id')->field($field)->where($where)->count();



        return ['count'=>$count,'list'=>$list];



    }

    public function  update_info($data){

        $list=$this->modelOtcInterestLog->where(['id'=>['in',$data['ids']],'state'=>1])->select();

        Db::startTrans();
        try{
            foreach ($list as $k=>$v){

                    $v->state=2;
                    $v->update_time=time();
                    $v->save();
                    $v->shop->number_do+=$v['coin_number'];
                    $v->shop->poundage_number+=$v['coin_number'];
                    $v->shop->save();



            }
            Db::commit();
            return    [RESULT_SUCCESS, '操作成功'];
         }catch (\Exception $e){

            Db::rollback();
            return  [RESULT_ERROR,$e->getMessage()];
        }


    }











}
